package com.example.administrator.hqq.adapter.module;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.util.Util;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.AddCheckedModuleBean;
import com.example.administrator.hqq.bean.AllModuleTopicBean;
import com.example.administrator.hqq.utils.BoldTextUtils;
import com.example.administrator.hqq.utils.transform.GlideRoundTransform;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/11/9 14:29
 * @remark:
 */
public class AddModuleGridView extends BaseAdapter {
    private Context context;
    private List<AllModuleTopicBean.DataBean.TopicBean>  list;
    private boolean aBoolean=true;
    public AddModuleGridView(Context context, List<AllModuleTopicBean.DataBean.TopicBean>  data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.add_module_item, viewGroup, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (aBoolean)
        if (i==list.size()-1)
        {
            aBoolean=false;
        }
        if(Util.isOnMainThread())
            Glide.with(context).load(list.get(i).getUrl())
                .override(474,370)
                .transform(new FitCenter(context),new GlideRoundTransform(context,4))
                .into(viewHolder.add);
        viewHolder.title.setText(list.get(i).getName());
        BoldTextUtils.BoldText(viewHolder.title);
        if (list.get(i).isSelect())
        {
            viewHolder.solid_circle.setSelected(true);
        }
        else{
            viewHolder.solid_circle.setSelected(false);
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.add)
        ImageView add;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.solid_circle)
        AutoRelativeLayout solid_circle;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
